#!/usr/bin/env sh
# Extract the introductory documentation into the README.md

set -e

awk 'BEGIN { take=1 }/# Approach/{take=0;print}take' < README.md > README.md.new
grep '^//!' rustls/src/lib.rs | \
       sed -e 's@^\/\/\! *@@g' | \
       sed -e 's@](manual::_04_features)@](https://docs.rs/rustls/latest/rustls/manual/_04_features/index.html)@' | \
       sed -e 's@\[`crypto::CryptoProvider`\]: crate::crypto::CryptoProvider@[`crypto::CryptoProvider`]: https://docs.rs/rustls/latest/rustls/crypto/struct.CryptoProvider.html@' | \
       awk '/# Rustls - a modern TLS library/{take=1;next}/## Design overview/{take=0}take' >> README.md.new
awk '/# Example code/{take=1}take' < README.md >> README.md.new
mv README.md.new README.md
